package cn.wolfcode.trip.base.domain;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;

/**
 * 攻略文章
 */
@Setter
@Getter
public class StrategyDetail extends BaseDomain {
    /**
     * 草稿
     */
    public static final int STATE_COMMON = 0;
    /**
     * 发布
     */
    public static final int STATE_RELEASE = 1;
    /**
     * 禁用
     */
    public static final int STATE_DISABLE = -1;

    //标题
    private String title;
    //创建时间
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT-8")
    private Date createTime;
    //发布时间
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date releaseTime;
    //序号
    private Integer sequence;
    //所属目录
    private StrategyCatalog catalog;
    //封面
    private String coverUrl;
    //状态
    private Integer state = STATE_COMMON;
    //攻略文章内容
    private StrategyContent content;

    public String getStateName() {
        String temp = "草稿";
        if (STATE_RELEASE == state) {
            temp = "发布";
        } else if (STATE_DISABLE == state) {
            temp = "禁用";
        }
        return temp;
    }

    public String getJson() {
        HashMap<String, Object> map = new HashMap<>(10);
        map.put("id", id);
        if (catalog != null) {
            map.put("catalogId", catalog.getId());
            map.put("catalogName", catalog.getName());
        }
        map.put("title", title);
        map.put("coverUrl", coverUrl);
        map.put("sequence", sequence);
        map.put("state", state);
        if (catalog!= null) {
            map.put("strategyId", catalog.getStrategy().getId());
        }
        return JSON.toJSONString(map);
    }
}